//
//  NextReservationViewController.m
//  LoveAttention
//
//  Created by 鞠超 on 15/12/30.
//  Copyright © 2015年 JC. All rights reserved.
//

#import "NextReservationViewController.h"

#import "DataProvider.h"
#import "SVProgressHUD.h"
#import "UIImageView+WebCache.h"
@interface NextReservationViewController ()

//@property (nonatomic, strong) UILabel * active;
//
//@property (nonatomic, strong) UILabel * time;
//
//@property (nonatomic, strong) UILabel * number;
//
//@property (nonatomic, strong) UILabel * detail;
//
//@property (nonatomic, strong) UILabel * name;
//
//@property (nonatomic, strong) UILabel * tel;
//
//@property (nonatomic, strong) UILabel * words;
//
//@property (nonatomic, strong) UIButton * btn_ok;
//
//@property (nonatomic, strong) UIButton * btn_cancal;
@end

@implementation NextReservationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navigationController];
    
    [self p_setupView];
    
    [self p_data];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - navigationController
- (void)p_navigationController
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.title = @"预约详情";
    UIButton * btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btn setBackgroundImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
        btn.frame = CGRectMake(10, 20, 25, 30);
    [btn addTarget:self action:@selector(leftBarButtonItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
}
//点击事件(左)
- (void)leftBarButtonItemAction:(UIBarButtonItem *)bar
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局
- (void)p_setupView
{
    UIView * view_bottom = [[UIView alloc] initWithFrame:CGRectMake(20 , 64 + 10, self.view.frame.size.width - 40, 155)];
    view_bottom.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_bottom];
    
    //活动
    UILabel * label_1 = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 50, 30)];
    label_1.text = @"活动:";
    label_1.font = [UIFont systemFontOfSize:15];
    label_1.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_1];
    
    self.active = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_1.frame) + 15, 5, 180, 30)];
    self.active.font = [UIFont systemFontOfSize:15];
    self.active.text = @"哈哈哈哈";
    [view_bottom addSubview:self.active];
    
    UIView * view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.active.frame) + 3, self.view.frame.size.width - 40, 1)];
    view_1.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_1];
    
    //时间
    UILabel * label_2 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(view_1.frame) + 5, 50, 30)];
    label_2.text = @"时间:";
    label_2.font = [UIFont systemFontOfSize:15];
    label_2.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_2];
    
    self.time = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_2.frame) + 15, CGRectGetMaxY(view_1.frame) + 5, 180, 30)];
    self.time.font = [UIFont systemFontOfSize:15];
    self.time.text = @"2015-08-31";
    [view_bottom addSubview:self.time];
    
    UIView * view_2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.time.frame) + 3, self.view.frame.size.width - 40, 1)];
    view_2.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_2];
    
    //人数
    UILabel * label_3 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(view_2.frame) + 5, 50, 30)];
    label_3.text = @"人数:";
    label_3.font = [UIFont systemFontOfSize:15];
    label_3.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_3];
    
    self.number = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_3.frame) + 15, CGRectGetMaxY(view_2.frame) + 5, 180, 30)];
    self.number.font = [UIFont systemFontOfSize:15];
    self.number.text = @"11人";
    [view_bottom addSubview:self.number];
    
    UIView * view_3 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.number.frame) + 3, self.view.frame.size.width - 40, 1)];
    view_3.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_3];
    
    //备注
    UILabel * label_4 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(view_3.frame) + 5, 50, 30)];
    label_4.text = @"备注:";
    label_4.font = [UIFont systemFontOfSize:15];
    label_4.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_4];
    
    self.detail = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_4.frame) + 15, CGRectGetMaxY(view_3.frame) + 5, 180, 30)];
    self.detail.font = [UIFont systemFontOfSize:15];
    self.detail.text = @"无备注";
    [view_bottom addSubview:self.detail];
    
    
    
    UIView * view_mid = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_bottom.frame) + 15, self.view.frame.size.width, 135)];
    view_mid.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_mid];
    
    //名字
    UIImageView * image_mid1 = [[UIImageView alloc] initWithFrame:CGRectMake(25, 10, 25, 25)];
    image_mid1.image = [UIImage imageNamed:@"xingming"];
//    image_mid1.backgroundColor = [UIColor orangeColor];
    [view_mid addSubview:image_mid1];
    
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_mid1.frame) + 15, 10, 200, 25)];
    self.name.text = @"张某某";
    self.name.font = [UIFont systemFontOfSize:17];
    [view_mid addSubview:self.name];
    
    UIView * view_mid1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.name.frame) + 10, self.view.frame.size.width, 1)];
    view_mid1.backgroundColor = [UIColor grayColor];
    [view_mid addSubview:view_mid1];
    
    //电话
    UIImageView * image_mid2 = [[UIImageView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(view_mid1.frame) + 10, 25, 25)];
    image_mid2.image = [UIImage imageNamed:@"dianhua"];
    [view_mid addSubview:image_mid2];
    
    self.tel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_mid2.frame) + 15, CGRectGetMaxY(view_mid1.frame) + 10, 200, 25)];
    self.tel.text = @"11111111111111";
    self.tel.font = [UIFont systemFontOfSize:17];
    [view_mid addSubview:self.tel];
    
    UIView * view_mid2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tel.frame) + 10, self.view.frame.size.width, 1)];
    view_mid2.backgroundColor = [UIColor grayColor];
    [view_mid addSubview:view_mid2];
    
    //电话
    UIImageView * image_mid3 = [[UIImageView alloc] initWithFrame:CGRectMake(25, CGRectGetMaxY(view_mid2.frame) + 10, 25, 25)];
    image_mid3.image = [UIImage imageNamed:@"3"];
    [view_mid addSubview:image_mid3];
    
    self.words = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_mid3.frame) + 15, CGRectGetMaxY(view_mid2.frame) + 10, self.view.frame.size.width - CGRectGetMaxX(image_mid3.frame) - 25, 25)];
    self.words.text = @"您已同意该用户的预约申请";
    self.words.textColor = [UIColor orangeColor];
    self.words.font = [UIFont systemFontOfSize:17];
    [view_mid addSubview:self.words];
    
//    //确认
//    self.btn_ok = [UIButton buttonWithType:(UIButtonTypeSystem)];
//    self.btn_ok.frame = CGRectMake(10, self.view.frame.size.height - 50, (self.view.frame.size.width - 30) / 2, 40);
//    [self.btn_ok setBackgroundImage:[UIImage imageNamed:@"reseration_comit"] forState:(UIControlStateNormal)];
//    [self.view addSubview:self.btn_ok];
//    [self.btn_ok addTarget:self action:@selector(btn_okAction:) forControlEvents:(UIControlEventTouchUpInside)];
//    
//    //取消
//    self.btn_cancal = [UIButton buttonWithType:(UIButtonTypeSystem)];
//    self.btn_cancal.frame = CGRectMake(CGRectGetMaxX(self.btn_ok.frame) + 10, self.view.frame.size.height - 50, (self.view.frame.size.width - 30) / 2, 40);
//    [self.btn_cancal setBackgroundImage:[UIImage imageNamed:@"reseration_cancel"] forState:(UIControlStateNormal)];
//    [self.view addSubview:self.btn_cancal];
//    [self.btn_cancal addTarget:self action:@selector(btn_cancalAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//#pragma mark - btn
////确认
//- (void)btn_okAction:(UIButton *)sender
//{
//    //修改订单状态
//    NSLog(@"ok");
//}
//
////取消
//- (void)btn_cancalAction:(UIButton *)sender
//{
//    NSLog(@"cancel");
//}

#pragma mark - 数据
- (void)p_data
{
    DataProvider * dataprovider = [[DataProvider alloc] init];
    [dataprovider setDelegateObject:self setBackFunctionName:@"ReservationDetail:"];
    
    [dataprovider ReservationDetailWith:self.reseratid];
}

- (void)ReservationDetail:(id )dict
{
    NSLog(@"%@",dict);
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            self.active.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"goodname"]];
            self.time.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"datetime"]];
            self.number.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"personNum"]];
            self.detail.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"otherinfo"]];
            self.name.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"username"]];
            self.tel.text = [NSString stringWithFormat:@"%@",dict[@"data"][@"mobile"]];
            
            switch ([dict[@"data"][@"rstate"] integerValue])
            {
                case 0:
                    self.words.text = @"用户向您提供预约申请,请确认";
                    break;
                case 1:
                    self.words.text = @"用户向您提供预约申请,已同意";
                    break;
                case 2:
                    self.words.text = @"用户向您提供预约申请,已取消";
                    break;
                case 3:
                    self.words.text = @"用户向您提供预约申请,已完成";
                    break;
                default:
                    break;
            }
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }

}












@end
